package EXtension.Controller;

import EXtension.FrameWork.EventSystem;
import EXtension.FrameWork.MyDelegate;
import code.MyThumbnail;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

public class StartPanelController{

    @FXML
    private BorderPane directoryTree;

    @FXML
    private Button btnCopy;

    @FXML
    private Button btnRename;

    @FXML
    private Button btnDelete;

    @FXML
    private Button btnPaste;

    @FXML
    private BorderPane thumbnailDisplay;

    private List<File>dir=new ArrayList<>();

    public void initialize() {

        EventSystem.instance.register(new MyDelegate("AddFile") {
            @Override
            public void execute(Object data) {

                MyThumbnail my=(MyThumbnail)data;
                my.isSelected.set(true);
                dir.add(my.selectedFile);
            }
        });
        EventSystem.instance.register(new MyDelegate("SingleChoose") {
            @Override
            public void execute(Object data) {
                dir.clear();
                MyThumbnail my=(MyThumbnail)data;
                dir.add(my.selectedFile);
            }
        });
        EventSystem.instance.register(new MyDelegate("MultiChoose") {
            @Override
            public void execute(Object data) {

            }
        });
        btnCopy.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                if(mouseEvent.getButton()==MouseButton.PRIMARY){
                    EventSystem.instance.SendEvent("Copy",dir);
                }
            }
        });
        btnPaste.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                if(mouseEvent.getButton()==MouseButton.PRIMARY){
                    EventSystem.instance.SendEvent("Paste",dir);
                }

            }
        });
        btnDelete.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                if(mouseEvent.getButton()==MouseButton.PRIMARY){
                    EventSystem.instance.SendEvent("Delete",dir);
                }

            }
        });
        btnRename.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                if(mouseEvent.getButton()==MouseButton.PRIMARY){
                    EventSystem.instance.SendEvent("Rename",dir);
                }

            }
        });
    }


    public BorderPane getDirectoryTree() {
        return directoryTree;
    }

    public void setDirectoryTree(BorderPane directoryTree) {
        this.directoryTree = directoryTree;
    }

    public BorderPane getThumbnailDisplay() {
        return thumbnailDisplay;
    }

    public void setThumbnailDisplay(BorderPane thumbnailDisplay) {
        this.thumbnailDisplay = thumbnailDisplay;
    }

    public Button getBtnCopy() {
        return btnCopy;
    }

    public void setBtnCopy(Button btnCopy) {
        this.btnCopy = btnCopy;
    }

    public Button getBtnRename() {
        return btnRename;
    }

    public void setBtnRename(Button btnRename) {
        this.btnRename = btnRename;
    }

    public Button getBtnDelete() {
        return btnDelete;
    }

    public void setBtnDelete(Button btnDelete) {
        this.btnDelete = btnDelete;
    }

    public Button getBtnPaste() {
        return btnPaste;
    }

    public void setBtnPaste(Button btnPaste) {
        this.btnPaste = btnPaste;
    }


}
